package com.wk.portal.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.wk.common.bean.Resp;
import com.wk.pms.entity.Category;
import com.wk.pms.vo.CategoryVO;
import com.wk.portal.service.PortalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("index")
public class PortalController {

    @Autowired
    private PortalService portalService;

    /**
     * 查询一级分类信息
     */
    @GetMapping("cates")
    public Resp<List<Category>> queryLv1Category(){
        List<Category> categorys = portalService.queryLv1Category();
        return Resp.ok(categorys);
    }

    /**
     * 将一级菜单的ID当做父ID查询二三级分类信息
     * 避免多次远程调用, 使用嵌套查询一次把一级菜单对应的二三级分类全部查出来
     */
    @GetMapping("cates/{pid}")
    public Resp<List<CategoryVO>> queryByPrentId(@PathVariable Long pid) {
        List<CategoryVO> categoryVOS = portalService.queryByPrentId(pid);
        return Resp.ok(categoryVOS);
    }

}
